Socket
Socket
Sign inDemoInstall

merge

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    merge

Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.


Version published
Maintainers
1
Install size
7.92 kB
Created

Package description

What is merge?

The merge npm package is a utility that allows you to merge multiple objects into one. It is useful when you want to combine configurations, settings, or other data structures in JavaScript. It performs a deep merge by default, meaning that it recursively merges properties of objects, but it can also be configured to perform a shallow merge.

What are merge's main functionalities?

Deep Merge

This feature allows for the deep merging of objects, meaning that nested objects will also be merged together. The code sample demonstrates merging two objects with nested properties.

{"const merge = require('merge');
const object1 = { a: 1, b: { c: 2 } };
const object2 = { b: { d: 3 }, e: 4 };
const mergedObject = merge(object1, object2);
console.log(mergedObject); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }"}

Shallow Merge

This feature allows for the shallow merging of objects, which means that it will not recursively merge nested objects. The code sample demonstrates merging two objects without combining the nested properties.

{"const merge = require('merge');
const object1 = { a: 1, b: { c: 2 } };
const object2 = { b: { d: 3 }, e: 4 };
const mergedObject = merge.recursive(false, object1, object2);
console.log(mergedObject); // Output: { a: 1, b: { d: 3 }, e: 4 }"}

Other packages similar to merge

Readme

Source

Merge

Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.

Node.js Usage

npm install merge --save
var merge = require('merge'), original, cloned;

console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}

original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;

console.log(original.x.y, cloned.x.y);
// -> 1, 2

console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }

Browser Usage

<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/merge.js"></script>
<script>
	var original, cloned;

	console.log(merge({one:'hello'}, {two: 'world'}));
	// -> {"one": "hello", "two": "world"}

	original = { x: { y: 1 } };
	cloned = merge(true, original);
	cloned.x.y++;

	console.log(original.x.y, cloned.x.y);
	// -> 1, 2

	console.log(merge.recursive(true, original, { x: { z: 2 } }));
	// -> {"x": { "y": 1, "z": 2 } }

</script>

Tests

npm test

Keywords

FAQs

Last updated on 27 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc